package main

import "fmt"

// 本质是一个指针
type Animal interface {
	Sleep()
	GetColor() string
	GetType() string
}

// 具体的类,通过实现接口所有的方法来实现接口
type Cat struct {
	color string
}

func (this *Cat) Sleep() {
	fmt.Println("Cat is Sleep")
}

func (this *Cat) GetColor() string {
	return this.color
}
func (this *Cat) GetType() string {
	return "Cat"
}

type Dog struct {
	color string
}

func (this *Dog) Sleep() {
	fmt.Println("Dog is Sleep")
}

func (this *Dog) GetColor() string {
	return this.color
}
func (this *Dog) GetType() string {
	return "Dog"
}

func main() {
	/*var animal Animal //接口的数据类型，父类指针
	animal = &Cat{"Green"}
	animal.Sleep() //调用的cat的Sleep方法，多态的体现

	animal = &Dog{"Yellow"}
	animal.Sleep() //调用Dog的Sleep方法，多态的体现*/

	cat := Cat{"Green"}
	dog := Dog{"Yellow"}

	showAnimal(&cat)
	showAnimal(&dog)

}

func showAnimal(annimal Animal) {
	annimal.Sleep() //多态
	fmt.Println("color=", annimal.GetColor())
	fmt.Println("type=", annimal.GetType())
}
